
import { requestData } from '@/api';
import { getUrlParams, getHashParams } from '@/utils/common';
import moment from 'moment';
moment.locale('zh-cn');
export const getDataType = () => {
  const typecode = getHashParams().tc || getUrlParams().typecode;
  const startTime = moment().startOf('days').format('YYYY-MM-DD HH') + ':00:00';
  const list = [
    { value: '1', label: '原始数据', startTime: '', endTime: '', isRange: false },
    { value: '2', label: '分钟数据', startTime: '', endTime: '', isRange: false },
    { value: '3', label: '小时数据', startTime, endTime: '', isRange: false },
    { value: '4', label: '日数据', startTime: '', endTime: '', isRange: false },
    { value: '7', label: '月数据', startTime: '', endTime: '', isRange: false },
    { value: '9', label: '年数据', startTime: '', endTime: '', isRange: false }
  ];
  const params = {
    url: `/service-base/category/list/${typecode}`,
    type: 'get'
  };
  return new Promise((resolve, reject) => {
    requestData(params).then(resp => {
      if (resp.success) {
        const catecodelist = resp.data.data.map(v => v.catecode);
        const options = list.filter(v => catecodelist.includes(v.value));
        if (options.length) {
          const o = options.find(v => v.value === '3');
          var value = o ? o.value : options[0].value;
        }
        resolve({ options, value });
      }
    });
  });
};

export const getDataTypeData = () => {
  const typecode = getHashParams().tc || getUrlParams().typecode;
  const params = {
    url: `/service-base/category/list/${typecode}`,
    type: 'get'
  };
  return new Promise((resolve, reject) => {
    requestData(params).then(resp => {
      if (resp.success) {
        resolve(resp.data.data);
      }
    });
  });
};
